const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const cors = require('koa2-cors');
const mongoose = require('mongoose');
const jwtAuth = require("koa-jwt");
const app = new Koa();

mongoose.connect('mongodb://localhost:27017/test', { useNewUrlParser: true }, (err) => {
    if (err) {
        console.error('Failed to connect to database');
    } else {
        console.error('Connecting database successfully');
    }
})
// 跨域解决
app.use(cors())

app.use(bodyParser())
// token校验,除了登录接口
// app.use(jwtAuth({ secret: 'thewall' }).unless({
//     // 登录接口不需要验证
//     path: [/^\/api\/login/]

// }));
// routes
const userRoutes = require('./routes/user')
app.use(userRoutes.routes(), userRoutes.allowedMethods());

app.listen(3000)